layui.use(['table','form','laydate','jquery'], function(){
    var table = layui.table;
    var form = layui.form;
    var laydate = layui.laydate;
    var $ = layui.$; //重点处
    //第一个实例
    table.render({
        elem: '#table_list',
        limit: 30,
        method: 'post',
        height: 350, //容器高度
        text: {none: '暂无相关数据'},
        toolbar:"#table_list_tool",
        cols: [[ //表头
            {type:'radio',width:30,fixed: 'left'},
            {field: 'sharesKey', title: '关键字', width:120,align:"center", templet(row){
                if(row.sharesKey =='current_price') {
                    return '当前价格';
                }else if(row.sharesKey=='net_assets') {
                    return '每股净资产';
                }else if(row.sharesKey=='debt_ratio'){
                    return '负债率';
                }else if(row.sharesKey=='increase'){
                    return '涨幅';
                }else{
                    return '未设置';
                }
             }},
            {field: 'serialNumber', title: '位置', width:80,align:"center",},
            {field: 'regex', title: '正则表达式', width:280,align:"center",},
            {field: 'xpath', title: 'xpath', align:"center",width:400},

        ]],
        parseData: function(result){
            return CommonUtil.layuiParseData(result);
        },
    });

    //搜索初始化
    form.on('submit(search)', function(data){
        //阻止表单跳转。如果需要表单跳转，去掉这段即可。 默认返回 false
        return CommonUtil.layuiInitSearch("table_list",data);
    });


    let url ='/logic/logic_shares_xpath_detail/listData'; //数据接口
    layui.$(function(){
        let masterId = layui.$("#id").val();
        if(CommonUtil.isNotEmpty(masterId)){
            layui.table.reload("table_list", {
                url: url,
                where: {masterId:masterId} //当前容器的全部表单字段，名值对形式：{name: value}
            },"data");
        }

    });
    let edit = function(url,title,width,height,obj){
        var checkStatus = layui.table.checkStatus(obj.config.id);
        let id = undefined;
        if(obj.event=="edit"){
            if(checkStatus.data.length==1){
                id = checkStatus.data[0].id;
            }else{
                return ;
            }
        }
        layer.open({
            type: 2,
            title: title, //不显示标题栏
            method:"post",
            area: [width+'px', height+'px'], //自定义文本域宽高
            shade: 0.5,
            id: 'edit', //设定一个id，防止重复弹出
            moveType: 1, //拖拽模式，0或者1
            content: url+ CommonUtil.isNotEmptyReturn(id,"?id="+id),
            yes: function(index, layero){
                layer.getChildFrame('#submit', index).click();
            },
            btn2: function(index, layero){
                layer.close(index);
            }
        });
    }
    //工具栏监听事件
    table.on('toolbar(table_list_filter)', function(obj){
        switch(obj.event){
            case 'add': CommonUtil.layuiEditPage("/logic/logic_shares_xpath_detail/editPage","新增",600,335,obj); break;
            case 'edit':                    edit("/logic/logic_shares_xpath_detail/editPage","修改",600,335,obj); break;
            case 'del': CommonUtil.layuiDeleteData("/logic/logic_shares_xpath_detail/removed","search",obj); break;
        };
    });
});


